package config

import (
	"cloud_worm/util/uconfig"
	"fmt"
)

type HttpSrvConfig struct {
	HttpServer 		HttpServer 		`json:"http_server"`
}

func (h *HttpSrvConfig) Parse(container uconfig.ConfContainer) error {
	if err := h.HttpServer.parse(container); err != nil {
		return err
	}
	return nil
}

type HttpServer struct {
	WebPort 		string			`json:"web_port"`
	AddrFlag 		string			`json:"addr_flag"`
}

func (h *HttpServer) parse(container uconfig.ConfContainer) error {
	runMode := container.String("run_mode")
	if runMode == "" {
		return fmt.Errorf("no run_mode exist")
	}
	runModePrefix := runMode + "::"

	h.WebPort = container.String(runModePrefix + "web_port")
	if h.WebPort == "" {
		return fmt.Errorf("config web_port error")
	}

	h.AddrFlag = container.String(runModePrefix + "addr_flag")
	return nil
}
